//婚礼商城路由
// 引入express模块
const express = require('express');
// 引入数据库连接池模块
const pool = require('../pool.js');
// 创建路由器对象
const r = express.Router();
//查询所有套餐name接口  http://127.0.0.1:3000/v1/in_shop_iname
r.get('/in_shop_iname',(req,res)=>{
	pool.query('select distinct iname,fid from in_shop_img',(err,result)=>{
		if(err) throw err
		if (result.length==0){
			res.send({code: 400,msg: "没查询到"})
		}else{
			res.send(result);
		}
	});
});
// 首页展示图   http://127.0.0.1:3000/v1/in_shop_img
r.get('/in_shop_img',(req,res)=>{
	pool.query('select * from in_shop_img',(err,result)=>{
		if(err) throw err
		if (result.length==0){
			res.send({code: 400,msg: "没查询到"})
		}else{
			res.send(result);
		}
	});
});
r.get('/in_shop_mid',(req,res)=>{
	pool.query('select mid from in_shop_img',(err,result)=>{
		if(err) throw err
		if (result.length==0){
			res.send({code: 400,msg: "没查询到"})
		}else{
			res.send(result);
		}
	});
});
r.get('/in_shop',(req,res)=>{
	pool.query('select * from in_shop',(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});
r.get('/in_shop_name',(req,res)=>{
	pool.query('select distinct iname from in_shop',(err,result)=>{
		if(err) throw err
		if (result.length==0){
			res.send({code: 400,msg: "没查询到"})
		}else{
			res.send(result);
		}
	});
});
r.get('/in_shop_show',(req,res)=>{
	pool.query('select * from in_shop ORDER BY sid DESC',(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});
// 商家精选接口 http://127.0.0.1:3000/v1/out_shoptap
r.get('/out_shoptap',(req,res)=>{
	pool.query('select * from out_shoptap',(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});

r.get('/out_shop_outname',(req,res)=>{
	pool.query('select distinct outname,fid from out_shop_img',(err,result)=>{
		if(err) throw err
		if (result.length==0){
			res.send({code: 400,msg: "没查询到"})
		}else{
			res.send(result);
		}
	});
});

r.get('/out_shop_outimg',(req,res)=>{
	pool.query('select * from out_shop_img',(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});

// in_shop页面内容接口
r.get('/in_content',(req,res)=>{
	let tid=req.query.tid
	pool.query('select * from in_content where tid=?',[tid],(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});

//out_shop接口
r.get('/out_shop',(req,res)=>{
	let sid = req.query.sid
	pool.query('select * from out_shop where sid=?',[sid],(err,result)=>{
		if (err) throw err
		if(result.length==0){
			res.send({code: 400,msg: "没查到"})
		}else{
			res.send(result)
		}
	})
});

// 导出用户路由模块
module.exports = r;